import { HTTP } from '../utils/http.js';
class classicModel extends HTTP{
    getLatest(sCallback)  {
      this.request({
        url: 'classic/latest',
        success: (res) => {
          sCallback(res)
          wx.setStorageSync('last', res.index)
          wx.setStorageSync(this._getKey(res.index), res)
        }
      })
    };
  getPrevious(index, nextOrPrevious,sCallback) {
    let key = nextOrPrevious == 'next' ? this._getKey(index + 1) : this._getKey(index - 1);
    let classic = wx.getStorageSync(key)
    if (classic){
      sCallback(classic)
    }else{
      this.request({
        url: `classic/${index}/${nextOrPrevious}`,
        success: (res) => {
          sCallback(res)
          wx.setStorageSync(key,res)
        }
      })
    }

  };
  first(index) {
    return index==1?true:false
  };
  last(index) {
    return wx.getStorageSync('last')==index?true:false
  };
  _getKey(index) {
    let key = 'classic-' + index
    return key
  }
};
  
export { classicModel }